home *** CD-ROM | disk | FTP | other *** search
- Path: beach.and.nl!usenet
- From: jos@and.nl (Jos A. Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: ERR with typedef...lvalue
- Date: 16 Feb 1996 10:35:14 GMT
- Organization: AND Operations Research B.V.
- Message-ID: <4g1ml2$ibo@beach.and.nl>
- References: <1996Feb15.190109@nyssa.swt.edu>
- NNTP-Posting-Host: klepzeiker.and.nl
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <1996Feb15.190109@nyssa.swt.edu>, kv09845@nyssa.swt.edu wrote:
-
- |The following is a program I can't seem to get to compile. It keeps giving me
- |an error. Would anyone happen to know why. I'm sure it's simple, but then, so
- |am I. Any help greatly appreciated.
-
- [ just the essentials: ]
-
- | typedef char STRING[81];
- |
- | STRING text, input_line;
- |
- | text = "this is the text string";
- | input_line = "this is the input_line string";
-
- [ the compiler diagnostics: ]
-
- | 683 text = "this is the text string";
- | ....1
- |%CC-E-NEEDLVALUE, (1) In this statement, "text" is not an lvalue, but occurs
- |in a context that requires one.
- |
- | 684 input_line = "this is the input_line string";
- | ....1
- |%CC-E-NEEDLVALUE, (1) In this statement, "input_line" is not an lvalue, but
- |occurs in a context that requires one.
-
- I love your compiler; I just love its verbose way of communicating with
- its user: In this statement, "input_line" is not an lvalue, but occurs
- in a context that requires one. And ever so right it is: the variables
- 'input_line' and 'text' are not (modifiable) lvalues; they're both just
- a bunch (an array) of modifiable lvalues.
-
- The left hand side of an expression operator needs a modifiable lvalue
- (some object that can be assigned to). C is just a simple language;
- there is no way one can assign multiple values to multiple modifiable
- lvalues in one sweep unless the collection of those lvalues happens
- to be an lvalue itself (e.g. structure assigments).
-
- A tedious way of solving this little problem is:
-
- input_line[0]= 't';
- input_line[1]= 'h';
- input_line[2]= 'i';
- /* etc. etc. */
-
- but a nicer way of putting it is:
-
- strcpy(input_line, "this is the input_line string");
-
- There's another solution though: if you want to initialize both
- STRINGs, there's no need to assign them afterwards:
-
- STRING input_line = "this is the input_line string";
-
- Note that this is not an assignment, it's an initialization, performed
- before the process starts running if the variables happen to be global
- objects or performed by some nitty-gritty code inserted by the compiler
- for you if those objects are local to some function.
-
- kind regards,
-
- Jos aka jos@and.nl (still ashamed about that nasty 1000! problem ;-)
- --
- Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
-
-